import { SelectData, _addData, _deleteData, _getData, _updateData } from '@/api/Base'
import { defineStore } from 'pinia'

export const useBaseStore = defineStore('Base', {
    state() {
        return {
            page: '1',
            size: '10',
            listData: [],
            total: 0,
            rowData:
            {
                username: '',
                email: '',
                time: '',
                remark: false,
                address: [],
                img: '',
            },
            SelectData: []

        }
    },
    actions: {
        // 获取所有数据
        async getlistData() {
            const params = { page: this.page, size: this.size }
            const { data } = await _getData(params)
            console.log(data);
            this.listData = data.result
            console.log(this.listData);
            this.total = data.total

        },
        // 删除
        async deleteData(id: any) {
            const { data: deleteData } = await _deleteData(id)
            console.log(deleteData);
            alert(deleteData.message)
        },
        // 添加
        async addBaseData() {
            let { data: addBase } = await _addData(this.rowData)
            console.log(addBase,'11111');

        },
        // 修改
        async updateBaseData() {
            let { data: updateBase } = await _updateData(this.rowData)
            console.log(updateBase,'22222');
            
        },
        // 查询
        async SelectBaseData(val:any){
            let { data: selectBase } = await SelectData(val)
            console.log(selectBase);
            if(selectBase.code){
                this.listData = selectBase.result
            this.total = selectBase.result.length
            }else{
                this.listData=[],
                this.total = 0
            }
            
            
        }
    }
})